let str:String = 'jimmy';
let num:Number = 24;
let bool:Boolean = false;
let u:undefined = undefined;
let n:null = null;
let obj:Object = {x:1};
// let big:bigint = 100n;
// let sym:symbol = Symbol('me');
// str = null;
type combine = string|number;
// let v:void = null;
//对象数组和混合数组呢？
let arr:string[] = ['1', '2'];
let arr1:Array<string> = ['1','2'];
let arr2:combine[] = [1, 'a'];
let arr3:Array<string|number> = [1, 'a'];
console.log('arr2:');
console.log(arr2);

interface Arrobj{
    name: String,
    age: number
}

let arr4:Arrobj[] = [{name: 'jimmy', age: 12}];

//声明函数
function sum(x: number, y:number){
    return x+y;
}

//函数表达式
let mySum:(x:number, y:number)=>number = function(x:number, y:number){
    return x+y;
}

// 接口定义函数类型
interface SearchFunc{
    (source: string, subString?: string): boolean
}

// 可选参数，返回值可以不定义类型？——可以
// 默认值的话不需要带 ?
function buildName(firstName: string, lastName:string = 'cat'){
    if(lastName){
        return firstName + ' ' +lastName;
    }else{
        return firstName;
    }
}
sum(11, 11);
console.log(buildName('liu'));
// buildName();

//剩余参数
function push(array: any[],...items: any[]){
    items.forEach(function(item){
        array.push(item);
    });
}

let a:Array<any> = [];
push(a,1,2,3,4,5);
console.log(a);

//重载
//后面是 分号 哈
function add(x: number, y: number):number;
function add(x: string, y: string): string;
function add(x: string, y: number): string;
function add(x: number, y: string): string;
function add(x: combine,y: combine){
    if(typeof x=='string' ||typeof y=='string'){
        return x.toString()+ y.toString();
    }
    return x+y;
}
console.log('add:');
let res = add(1,2);
console.log(res);
console.log('add1:');
let res1 = add('1','2');
console.log(res1);
console.log(res1.split(''));

let t: [string, number];
t = ['hello', 10];
// t = ['hello', 10];
console.log(t);

let [na, age] = t;

const point: readonly [number, number] = [10, 10];
// point[0] = 1;

let vv:void;

function func(): void{
    console.log('this is typescript');
}

func();

function err(msg: string):never{
    throw new Error(msg);
}

// err('I am wrong');

type Foo = string | number;
function control(foo: Foo){
    if(typeof foo == 'string'){

    }else if(typeof foo == 'number'){
        
    }
    else{
        const check:never = foo;
    }
}

// control(true);

let aaa:any = 123;
let nev:never;
aaa = nev;
aaa = 123;
aaa = null;
aaa = undefined;

let bbb:string;
bbb = aaa;
// aaa = bbb;
//unknown 只能赋值给 unknown 和 any，任意值可以赋值给 unknown
let kk:unknown;
// aaa = kk;

const dog: unknown = { hello: 'world' };
// dog.hello;

function getDogName(){
    let x: unknown;
    return x;
}

let dogName = getDogName();
// if(typeof dogName === 'string'){
//     let upName = dogName.toLowerCase();
// }
// let upName = (dogName as string).toLowerCase();

// 可以将 string、number、boolean、{} 赋值给 Object
let obj1:Object;
obj1 = 1;
obj1 = 'a';
obj1 = true;
obj1 = {};

//只能将 {}  赋值给 object 类型
let obj2:object;
obj2 = {};
// obj1=obj2;
// obj2 = obj1;

type extendObj = object extends Object?string:number;
type extendobj = Object extends object?string:number;

// console.log(extendObj);
let par1:extendObj = '123';
let par2:extendobj = '123';

let Num:Number = 1234;
let num1:number = 123;
// num1=Num;
// Num=num1;

let myFavoriteNumber;
myFavoriteNumber = 'serven';
myFavoriteNumber = 7;

function add1(x: number, y: number){
    return x + y;
}

class A{
    str:string;
    private str1: number = 1;

    constructor(name: string, age: number){
        this.str = name;
    }

    getStr(){
        this.str = 'win7';
        console.log(`str1: ${this.str}`);
    }
}
let aa = new A('katy', 31);
console.log(aa.str);
// console.log(A.str1);
aa.getStr();

interface ILoan{
    interest: number
}
//实现接口还得自己重写，这样真的好？
class Agr implements ILoan{
    interest: number
    rebate: number

    constructor(interest: number, rebate: number){
        this.interest = interest;
        this.rebate = rebate;
    }
}

var agr = new Agr(10, 1);
console.log(`利润为：${agr.interest}, 抽成为：${agr.rebate}`);

var sites = {
    site1: 'Runoob',
    site2: 'Google',
    sayHello: function(){}  //这里不写，下面定义函数就会报错
};
sites.sayHello = function(){

}
/// <reference path="circle.ts"/>

namespace Drawing{
    export class Circle implements IShape{
        // 公共方法居然
        public draw(){
            console.log('Circle is drown');
        }
    }
}